package com.qualityin.mall.demo.controller;

import com.github.pagehelper.Page;
import com.qualityin.mall.common.util.web.bean.GenericController;
import com.qualityin.mall.common.util.web.bean.ResponseBean;
import com.qualityin.mall.demo.entity.Demo;
import com.qualityin.mall.demo.entity.QueryDemo;
import com.qualityin.mall.demo.service.DemoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.ws.rs.*;
import java.util.Map;

//import javax.ws.rs.PathParam;

/**
 * @Description:
 * @author:Steven
 * @date 2016/10/26 12:04
 */
@Path("demoService") // 服务路径
@Controller()
@Produces("application/json")
public class DemoController extends GenericController {
	@Resource
	DemoService demoSerice;
	/**
	 * 保存demo，包括新增和修改
	 * @param demo
	 * @return
	 */
	@RequestMapping(value="/saveDemo")
	@ResponseBody
	public ResponseBean saveDemo(Demo demo){
		demoSerice.saveDemo(demo);
		return ResponseBean.responseSuccess("保存成功!");
	}
	/**
	 * 删除demo
	 * @param id
	 * @return
	 */
	@Path(value="/deleteDemo")
	public ResponseBean deleteDemo(@RequestParam int id){
		demoSerice.deleteDemo(id);
		return ResponseBean.responseSuccess("删除成功!");
	}
	@GET
	@Path("/demo/{id}")
	public ResponseBean getDemo(@PathParam("id") Integer id){
		return ResponseBean.responseSuccess(demoSerice.getDemo(id));
	}
	/**
	 * 获取demo列表
	 * @return
	 */
	@GET
	@Path("/demo/list")
	public ResponseBean getDemoList(QueryDemo queryDemo){
		return ResponseBean.responseSuccess(queryDemo);
	}
	@POST
	@Path("/demo/list1")
	@Produces("application/json")
		public ResponseBean getDemoList1(QueryDemo queryDemo){
		return ResponseBean.responseSuccessForPage((Page) demoSerice.getDemoList(queryDemo),queryDemo);
	}
}
